//
//  MyScrollView.m
//  UI6_轮播
//
//  Created by dllo on 16/3/16.
//  Copyright © 2016年 www.lanou.com 蓝欧科技. All rights reserved.
//

#import "MyScrollView.h"

@implementation MyScrollView
- (instancetype)initWithFrame:(CGRect)frame imageArr:(NSArray<UIImage *> *)imageArr delegate:(id)delegate
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView:frame imageArr:imageArr delegate:delegate];
    }
    return self;
}
- (void)createSubView:(CGRect)frame
             imageArr:(NSArray *)imageArr
             delegate:(id)delegate

{
    // 设置大的ScrollView的偏移量(大的ScrollView控制轮播, 小的控制缩放)
    self.contentSize = CGSizeMake(frame.size.width * imageArr.count, 0);
   // 最开始时候显示第一张
    self.contentOffset = CGPointMake(frame.size.width, 0);
    for (int i = 0; i < imageArr.count; i++) {
        
        // 创建小的ScrollView控制缩放
        UIScrollView *smallScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(i * frame.size.width, 0, frame.size.width, frame.size.height)];
        // 最小缩放比例
        smallScrollView.minimumZoomScale = 0.5;
        // 最大缩放比例
        smallScrollView.maximumZoomScale = 2;
        // 添加到大的ScrollView上
        [self addSubview:smallScrollView];
        // 设置代理人
        smallScrollView.delegate = delegate;
        
        // 相框
        UIImageView *imageView = [[UIImageView alloc]initWithImage:imageArr[i]];
        imageView.frame = CGRectMake(0, 0, frame.size.width, frame.size.height);
        // 开启用户交互
        imageView.userInteractionEnabled = YES;
        [smallScrollView addSubview:imageView];
        
        
    }
    self.pagingEnabled = YES;
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
